﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace Gakita.Model.Miscellaneous
{
    /* This class handles the logic for the FlyingPlatform. FlyingPlatforms are platforms which moves back and forth horizontally and that          the player can jump/stand on. */
    class FlyingPlatform
    {
        private Vector2 _topLeftPosition;
        private Vector2 _startPosition;
        private float _distanceToTravel;
        private Vector2 _speed              =       new Vector2(3, 0);
        private Vector2 _size               =       new Vector2(2, 1);

        public FlyingPlatform(Vector2 aPosition, float aDistanceToTravel)
        {
            _topLeftPosition = aPosition;
            _startPosition = _topLeftPosition;

            _distanceToTravel = aDistanceToTravel;
        }

        public void Update(float aElapsedTime)
        {
            if (ItIsTimeToTurnAround())
            {
                TurnAround();
            }

            _topLeftPosition += _speed * aElapsedTime;
        }

        /* This method checks if the platform has moved a certain distance from its' starting position, and should turn around */
        private bool ItIsTimeToTurnAround()
        {
            if (_topLeftPosition.X < _startPosition.X || _topLeftPosition.X > _startPosition.X + _distanceToTravel)
                {
                    return true;
                }
            return false;
        }

        /* This method turns the platform around by reversing its' speed */
        private void TurnAround()
        {
            _speed = -_speed;
        }

        public Vector2 GetPosition()
        {
            return _topLeftPosition;
        }

        public Vector2 GetSize()
        {
            return _size;
        }

        public Vector2 getPlatformSpeed()
        {
            return _speed;
        }
    }
}
